const staff = require('../models/staff')

// 获取全部员工
const getStaffs = async (ctx) => {
  const query = ctx.request.query
  const data = await staff.getStaffs(query)
  ctx.body = {
    code: 0,
    message: '成功',
    data
  }
}
// 根据关键字获取员工
const getStaffByKeyWords = async (ctx) => {
  const keywords = ctx.request.query
  const data = await staff.getStaffByKeyWords(keywords)
  if(data) {
    ctx.body = {
      code: 0,
      message: '成功',
      data
    }
  }else {
    ctx.body = {
      code: -1,
      message: '失败'
    }
  }
}
// 根据id获取员工
const getStaffById = async (data) => {
  const result = await staff.getStaffById(data)
  return result
}

// 根据id修改员工
const updateStaff = async (data, id) => {
  const result = await staff.updateStaff(data, id)
  return result
}

// 新增员工
const addStaff = async (data) => {
  const result = await staff.addStaff(data)
  return result
}

// 根据id删除员工
const deleteStaff = async (data) => {
  await staff.deleteStaff(data)
  return true
}

// 根据id更新员工状态
const updateStatus = async (data, id) => {
  await staff.updateStatus(data, id)
}
module.exports = {
  getStaffs,
  getStaffByKeyWords,
  getStaffById,
  updateStaff,
  addStaff,
  deleteStaff,
  updateStatus
}